package im.vinci.server.headphone.persistence;

import im.vinci.server.headphone.domain.BarrageText;
import im.vinci.server.headphone.domain.VisualBrandCategory;
import im.vinci.server.headphone.domain.VisualData;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.List;

/**
 * Created by mingjie on 17/3/6.
 */
@Repository
public interface VisualDataMapper {
    @Select("SELECT category,title,pic,video_file,file_hash,priority FROM visual_data WHERE language=#{language} AND is_deleted=0")
    List<VisualData> select(@Param("language") String language);

    @Select("SELECT text,create_time,is_deleted FROM visual_barrage_text WHERE language=#{language} ORDER BY create_time DESC")
    List<BarrageText> selectBarrageText(@Param("language") String language);

    @Select("SELECT brand,category FROM visual_brand_category WHERE device_id=#{device_id} AND is_deleted=0")
    List<VisualBrandCategory> selectBrandCategory(@Param("device_id") String deviceId);

    @Select({"<script>",
            "SELECT category,title,pic,video_file,file_hash,priority FROM visual_brand_data WHERE is_deleted=0 AND category IN ",
            "<foreach item='item' index='index' collection='list' open='(' separator=',' close=')'>",
            "#{item}",
            "</foreach>",
            "</script>"})
    List<VisualData> selectBrandData(@Param("list") Collection<String> categorySet);
}
